SEE Wiki Scrapbook Bookmarklet 2.0 - below is superseded by "Clipping Bookmarklet" method!
Goal: One-click capture of interesting items of information from web pages, with a reference back to that page.
Method: Catch information thrown from a bookmarklet, and append that information to an existing ZhurnalyWiki page. See Scrapbook Bookmarklet Version 0.1 for background on what a "bookmarklet" is.
Bookmarklet Code: Create a bookmarklet with javascript like:
javascript:location.href='http://zhurnaly.com/cgi-bin/wiki?action=scrapbook;id=SandBox;url='+encodeURIComponent(location.href)+';scrap='+encodeURIComponent(window.getSelection())
When clicked, this produces a URL that looks like:
http://zhurnaly.com/cgi-bin/wiki?action=scrapbook;id=SandBox;url=http%3A%2F%2Fwww.oddmuse.org;scrap=Oddmuse%20is%20a%20wiki%20engine
which would be generated if the user highlighted the words "Oddmuse is a wiki engine" on the Oddmuse main page http://www.oddmuse.org and then clicked the bookmarklet link to execute that Javascript.
Wiki Extension Code: To append information to a page on ZhurnalyWiki, which uses the Oddmuse wiki engine, the following Perl script is an Oddmuse extension module. It puts the reference page URL (from which the highlighted scrap comes) into double-square-brackets, so there's no problem with a trailing "." in a URL. (The Oddmuse parser apparently does what's usually the right thing and doesn't include a period at the end of a URL in the link, since generally it's the end of a sentence.) The code changes newlines into double-newlines so that the copy/paste scrap looks more reasonable in the wiki.
# SCRAPBOOK --- by Mark Zimmermann --- http://zhurnaly.com
# based on like.pl by Alex Schroeder & Ingo Belka with additional help from Alex
# catches inputs from bookmarklet that sends URL and highlighted web text to be saved
# and appends to chosen wiki page
# here's a sample bookmarklet, which appends scraps to the SandBox:
# javascript:location.href='http://zhurnaly.com/cgi-bin/wiki?action=scrapbook;id=SandBox;url='+encodeURIComponent(location.href)+';scrap='+encodeURIComponent(window.getSelection())
$ModulesDescription .= '<p>$Id: scrapbook.pl,v 0.2 2011-12-20 00:00:00 zhurnaly Exp $</p>';
$Action{scrapbook} = \&DoScrapbook;
sub DoScrapbook {
my $id = shift;
my $url = GetParam('url');
my $scrap = GetParam('scrap');
OpenPage(FreeToNormal($id));
# change all newlines in scrap into double newlines for better appearance of result
$scrap =~ s/\n/\n\n/g;
my $data = $Page{text};
$data .= "\n----\n[[$url]]\n\n$scrap\n";
SetParam('text', $data);
SetParam('title', $OpenPageName);
SetParam('oldtime', $Page{ts});
SetParam('recent_edit', 'on');
SetParam('summary', T('scrapbooking!'));
DoPost($id);
}
Next Step: Consider how to allow the user to create a new ZhurnalyWiki page out of a highlighted selection, perhaps by creating a dialog box to put that new page name into (instead of defaulting to the same SandBox (or whatever) page every time).
Acknowledgements: Many thanks to Alex Schroeder and comrades on http://oddmuse.org for writing the Oddmuse wiki engine and sharing their enthusiastic expertise in extending it.
(cf. Scrapbook Bookmarklet Version 0.1, http://www.oddmuse.org/cgi-bin/oddmuse/Comments_on_Clipping_Bookmarklet, ...) - ^z - 2012-01-11